//
//  ChengXinViewController.m
//  DaJiHui
//
//  Created by Hao on 2017/7/6.
//  Copyright © 2017年 Hao. All rights reserved.
//
#define ZMY_WIDTH [UIScreen mainScreen].bounds.size.width
#define ZMY_HEIGHT [UIScreen mainScreen].bounds.size.height
#define MANAGER [AFHTTPSessionManager manager]
#import "NSArray+CZSafeAccess.h"
#import "AFNetworking.h"
#import "CollectionModel.h"
#import "CollectionViewCell.h"
#import "ViewController.h"
#import "UIImageView+WebCache.h"
#import "MMComBoBox.h"
#import "DOPDropDownMenu.h"
#import "ChengXinViewController.h"

@interface ChengXinViewController ()<DOPDropDownMenuDataSource,DOPDropDownMenuDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collection;
@property (nonatomic, strong) NSArray *mutableArray;
@property (nonatomic, weak) DOPDropDownMenu *menu;
@property (nonatomic, strong) MMComBoBoxView *comBoBoxView;
@property (nonatomic, strong) NSArray *hostels;
@property (nonatomic, strong) NSArray *areas;
@property (nonatomic, strong) NSArray *sorts;
@property (nonatomic, strong) NSArray *four;

@property (nonatomic, strong) NSMutableArray *hostelsr;
@property (nonatomic, strong) NSMutableArray *areasr;
@property (nonatomic, strong) NSMutableArray *sortsr;
@property (nonatomic, strong) NSMutableArray *fourr;

@property (nonatomic, strong) NSMutableArray *hostelsid;
@property (nonatomic, strong) NSMutableArray *areasid;
@property (nonatomic, strong) NSMutableArray *sortsid;
@property (nonatomic, strong) NSMutableArray *fourid;


@property (nonatomic, strong) NSString *strY;
@property (nonatomic, strong) NSString *strT;
@property (nonatomic, strong) NSString *strD;


@end

@implementation ChengXinViewController

{
    NSArray*TypeArr;
    NSMutableArray * _dataArrayM;
    UICollectionView * _collectionView;
    UICollectionViewFlowLayout *_collectionVFL;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeBaseUI];
    self.view.backgroundColor= [UIColor whiteColor];
    _dataArrayM = [NSMutableArray array];
    [self getData];
    
    // Do any additional setup after loading the view.
}
- (void)getData{
    _hostels = [[NSArray alloc]init];
    _hostelsr = [[NSMutableArray alloc]init];
    _hostelsid = [[NSMutableArray alloc]init];
    _fourr = [[NSMutableArray alloc]init];
    
    _areas = [[NSArray alloc]init];
    _areasr = [[NSMutableArray alloc]init];
    _areasid = [[NSMutableArray alloc]init];
    
    _sorts = [[NSArray alloc]init];
    _sortsr = [[NSMutableArray alloc]init];
    _sortsid = [[NSMutableArray alloc]init];
    
    
    MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
    MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
    NSString * str = @"http://www.chaojihui123.com/phonedata.php?s=/Index/warelist/waretype/2";
    [MANAGER GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"%@",responseObject);
        _fourr = [NSMutableArray array];
        if (responseObject[@"res"]&&[responseObject[@"res"] isKindOfClass:[NSArray class]]) {
            _fourr = responseObject[@"res"];
            for (int i = 0; i < _fourr.count; i ++) {
                NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:_fourr[i]];
                CollectionModel * model = [[CollectionModel alloc]init];
                model.storename = dict[@"storename"];
                model.title = dict[@"title"];
                model.oprice = dict[@"oprice"];
                model.price = dict[@"price"];
                model.pic1 = dict[@"pic1"];
                [_dataArrayM addObject:model];
                
            }

        }
        
        
        _hostels = responseObject[@"restwo"];
        _areas = responseObject[@"resone"];
        _sorts = responseObject[@"loares"];
        for (NSMutableDictionary *dic in _hostels)
        {
            NSLog(@"%@", dic);
            [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
            [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            
            NSLog(@"hostelsa ==%@",self.hostelsr);
            NSLog(@"hostelsaid ==%@",self.hostelsid);
            
        }
        
        [_hostelsr insertObject:@"行业" atIndex:0];
        
        for (NSMutableDictionary *dic in _areas)
        {
            NSLog(@"%@", dic);
            [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
            
            [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            
            NSLog(@"areasa==%@",self.areasr);
            
            NSLog(@"areasaid==%@",self.areasid);
            
        }
        [_areasr insertObject:@"分类" atIndex:0];
        
        
        for (NSMutableDictionary *dic in _sorts)
        {
            NSLog(@"%@", dic);
            [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
            [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
            NSLog(@"sortsa==%@",self.sortsr);
            NSLog(@"sortsaid==%@",self.sortsid);
            
        }
        [_sortsr insertObject:@"地区" atIndex:0];
                [self bulidUI];
        //        dispatch_async(dispatch_get_main_queue(), ^{
        //            [self.collection reloadData];
        //
        //        });
        [self.menu reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

- (void)bulidUI{
    // 设置布局
    _collectionVFL = [[UICollectionViewFlowLayout alloc] init];
    // 设置滑动方向
    _collectionVFL.scrollDirection = UICollectionViewScrollDirectionVertical;
    _collectionVFL.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    // 设置item 大小
    // 默认值 50，50
    //    _collectionVFL.itemSize = CGSizeMake(100, 100);
    
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 44, ZMY_WIDTH, ZMY_HEIGHT ) collectionViewLayout:_collectionVFL];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_collectionView];
    
    // 注册cell
    [_collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"myCell"];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * ID = @"myCell";
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    CollectionModel * model = _dataArrayM[indexPath.row];
    cell.backgroundColor = [UIColor getColorFromRGBString:@"#F7F6F7"];
    cell.model = model;
    //    NSMutableString * str = (NSMutableString *)model.pic1;
    //    [str deleteCharactersInRange:NSMakeRange(0, 8)];
    //    [cell.pic1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.chaojihui123.com%@",str]]];
    return cell;
}

#pragma mark - 返回item组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

#pragma mark - 返回item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArrayM.count;
}

#pragma mark - 返回item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(ZMY_WIDTH / 2 - 15, 200);
    
}

- (void)makeBaseUI{
    //    self.hostels = @[@"经济酒店",@"商务酒店",@"连锁酒店",@"度假酒店",@"公寓酒店",@"雨花区",@"雨花区",@"雨花区",@"雨花区"];
    //    self.areas = @[@"全城",@"芙蓉区",@"雨花区",@"天心区",@"开福区",@"岳麓区"];
    //    self.sorts = @[@"默认排序",@"离我最近",@"好评优先",@"人气优先",@"最新发布"];
    _four = @[@"排序",@"销量",@"价格",@"好评",@"发布时间"];
    DOPDropDownMenu *menu = [[DOPDropDownMenu alloc] initWithOrigin:CGPointMake(0, 0) andHeight:44];
    menu.delegate = self;
    menu.dataSource = self;
    [self.view addSubview:menu];
    _menu = menu;
    //     创建menu 第一次显示 不会调用点击代理，可以用这个手动调用
    //    [menu selectDefalutIndexPath];
    [menu selectIndexPath:[DOPIndexPath indexPathWithCol:0 row:0 item:0]];
    
}
- (NSInteger)numberOfColumnsInMenu:(DOPDropDownMenu *)menu
{
    return 4;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column
{
    if (column == 0) {
        return self.hostelsr.count;
    }else if (column == 1){
        return self.areasr.count;
    }else if (column == 2){
        return self.sortsr.count;
    }else {
        return self.four.count;
    }
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        return [_areasr cz_objectWithIndex:indexPath.row];
    } else if (indexPath.column == 1){
        return [_hostelsr cz_objectWithIndex:indexPath.row];
    }else if (indexPath.column == 2){
        return [_sortsr cz_objectWithIndex:indexPath.row];
    }else {
        return[_four cz_objectWithIndex:indexPath.row];
    }
}

// new datasource

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForRowAtIndexPath:(DOPIndexPath *)indexPath
{
    return nil;
}

- (NSString *)menu:(DOPDropDownMenu *)menu imageNameForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    return nil;
}

- (NSInteger)menu:(DOPDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column
{
    return 0;
}

- (NSString *)menu:(DOPDropDownMenu *)menu titleForItemsInRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.column == 0) {
        return TypeArr[indexPath.row];
    } else if (indexPath.column == 1){
        return TypeArr[indexPath.row];
    } else {
        return TypeArr[indexPath.row];
    }
}

- (void)menu:(DOPDropDownMenu *)menu didSelectRowAtIndexPath:(DOPIndexPath *)indexPath
{
    if (indexPath.item >= 0) {
        NSLog(@"点击了 %ld - %ld - %ld 项目",indexPath.column,indexPath.row,indexPath.item);
    }else {
        if (indexPath.column==0) {
            if (indexPath.row==0) {
                
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString * str = @"http://www.chaojihui123.com/phonedata.php?s=/Index/warelist/waretype/2";
                [MANAGER GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    [self bulidUI];
                    
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
                
            }else{
                NSLog(@"点击了4 %ld - 5%ld 项目",indexPath.column,indexPath.row);
                
                _strY=_areasid[indexPath.row-1];
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString *str1 = [NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/hangye/%@",_strY];
                NSURL *url = [NSURL URLWithString:str1];
                [MANAGER GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                        dispatch_async(dispatch_get_main_queue(), ^{
                            [self.collection reloadData];
                            
                        });
                    }
                    [self bulidUI];
                    
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
                
            }
            
        }else if (indexPath.column==1){
            if (indexPath.row == 0) {
                return;
            }else{
                NSLog(@"点击了4 %ld - 5%ld 项目",indexPath.column,indexPath.row);
                
                _strT=_hostelsid[indexPath.row-1];
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString *str1 = [NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/hangye/%@/yingye/%@",_strY,_strT];
                NSURL *url = [NSURL URLWithString:str1];
                [MANAGER GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    [self bulidUI];
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
                
            }
        }else if (indexPath.column==2){
            if (indexPath.row==0) {
                return;
            }else{
                
                NSLog(@"点击了4 %ld - 5%ld 项目",indexPath.column,indexPath.row);
                
                _strD=_sortsid[indexPath.row-1];
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString *str1 = [NSString stringWithFormat:@"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/hangye/%@/yingye/%@/locationa/%@",_strY,_strT,_strD];
                NSURL *url = [NSURL URLWithString:str1];
                [MANAGER GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
                
            }
        }else if (indexPath.column ==3){
            if (indexPath.row == 0) {
                return;
            }else if (indexPath.row==1){
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString * str = @"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/xl/1";
                [MANAGER GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    
                    
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
            }else if (indexPath.row==2){
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString * str = @"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/jiage/1";
                [MANAGER GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    [self bulidUI];
                    
                    
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
                
                
            }else if (indexPath.row==3){
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString * str = @"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/pj/1";
                [MANAGER GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    [self bulidUI];
                    
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
                
            }else if (indexPath.row==4){
                _hostels = [[NSArray alloc]init];
                _hostelsr = [[NSMutableArray alloc]init];
                _hostelsid = [[NSMutableArray alloc]init];
                
                _areas = [[NSArray alloc]init];
                _areasr = [[NSMutableArray alloc]init];
                _areasid = [[NSMutableArray alloc]init];
                
                _sorts = [[NSArray alloc]init];
                _sortsr = [[NSMutableArray alloc]init];
                _sortsid = [[NSMutableArray alloc]init];
                
                _dataArrayM = [[NSMutableArray alloc]init];
                
                MANAGER.responseSerializer = [AFJSONResponseSerializer serializer];
                MANAGER.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"text/plain",@"application/json", nil];
                NSString * str = @"http://www.chaojihui123.com/phonedata.php?s=Index/warelist/time/1";
                [MANAGER GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                    NSLog(@"%@",responseObject);
                    NSArray * array = [NSArray arrayWithArray:responseObject[@"res"]];
                    _hostels = responseObject[@"restwo"];
                    _areas = responseObject[@"resone"];
                    _sorts = responseObject[@"loares"];
                    for (NSMutableDictionary *dic in _hostels)
                    {
                        NSLog(@"%@", dic);
                        [_hostelsr addObject:[NSString stringWithFormat:@"%@",dic[@"indnametwo"]]];
                        [_hostelsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"hostelsa ==%@",self.hostelsr);
                        NSLog(@"hostelsaid ==%@",self.hostelsid);
                        
                    }
                    
                    [_hostelsr insertObject:@"行业" atIndex:0];
                    
                    for (NSMutableDictionary *dic in _areas)
                    {
                        NSLog(@"%@", dic);
                        [_areasr addObject:[NSString stringWithFormat:@"%@",dic[@"indnameone"]]];
                        
                        [_areasid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        
                        NSLog(@"areasa==%@",self.areasr);
                        
                        NSLog(@"areasaid==%@",self.areasid);
                        
                    }
                    [_areasr insertObject:@"分类" atIndex:0];
                    
                    
                    for (NSMutableDictionary *dic in _sorts)
                    {
                        NSLog(@"%@", dic);
                        [_sortsr addObject:[NSString stringWithFormat:@"%@",dic[@"name"]]];
                        [_sortsid addObject:[NSString stringWithFormat:@"%@",dic[@"id"]]];
                        NSLog(@"sortsa==%@",self.sortsr);
                        NSLog(@"sortsaid==%@",self.sortsid);
                        
                    }
                    [_sortsr insertObject:@"地区" atIndex:0];
                    
                    for (int i = 0; i < array.count; i ++) {
                        NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:array[i]];
                        CollectionModel * model = [[CollectionModel alloc]init];
                        model.storename = dict[@"storename"];
                        model.title = dict[@"title"];
                        model.oprice = dict[@"oprice"];
                        model.price = dict[@"price"];
                        model.pic1 = dict[@"pic1"];
                        [_dataArrayM addObject:model];
                    }
                    [self bulidUI];
                    
                } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                    
                }];
                
            }
        }
        
        NSLog(@"点击了 %ld - %ld 项目",indexPath.column,indexPath.row);
    }
}
-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
